package com.supreme.studyserver;

import lombok.SneakyThrows;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@EnableAsync
@SpringBootApplication
public class SupremeStudyServerApplication {

    public static void main(String[] args) {
        String userDir = System.getProperty("user.dir");
        Path logsPath = Paths.get(userDir, "logs", "study-logs");
        try {
            boolean isDirectory = Files.isDirectory(logsPath);
            if (isDirectory) {
                try (Stream<Path> pathStream = Files.walk(logsPath)) {
                    pathStream.forEach(path -> {
                        if (Files.isRegularFile(path)) {
                            try {
                                Files.delete(path);
                            } catch (IOException e) {
                                System.out.println("e.getMessage() = " + e.getMessage());
                            }
                        }
                    });
                }
            }
            boolean deleteIfExists = Files.deleteIfExists(logsPath);
            System.out.println("deleteIfExists = " + deleteIfExists);
        } catch (IOException e) {
            System.out.println("deleteIfExists = " + e.getMessage());
        }

        SpringApplication.run(SupremeStudyServerApplication.class, args);
        final Charset charset = Charset.defaultCharset();
        System.out.printf("\n\t ↖(▔▽▔)↗ SupremeStudyServerApplication Charset=%s 启动完成 ↖(▔▽▔)↗ \n\n", charset);
        System.out.println(" ____ _____ _   _ ______   __  ____  _____ ______     _______ ____\n" +
                "/ ___|_   _| | | |  _ \\ \\ / / / ___|| ____|  _ \\ \\   / / ____|  _ \\\n" +
                "\\___ \\ | | | | | | | | \\ V /  \\___ \\|  _| | |_) \\ \\ / /|  _| | |_) |\n" +
                " ___) || | | |_| | |_| || |    ___) | |___|  _ < \\ V / | |___|  _ <\n" +
                "|____/ |_|  \\___/|____/ |_|   |____/|_____|_| \\_\\ \\_/  |_____|_| \\_\\");
    }

}
